"""
这是商机页面类
"""
#引入基类
from framwork.pages.base_page import BasePage
#引入by方法
from selenium.webdriver.common.by import By
#引入断言失败异常
from selenium.common.exceptions import NoSuchElementException

class OpportunityPage(BasePage):
    """先写定位器，再写方法"""
    add_sj_btn_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > a")
    #商机添加成功locator
    tips_success_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")
    #商机推进成功locator
    push_success_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")
    #商机页面勾选框
    gx_locator = (By.NAME, "business_id[]")
    delete_locator = (By.ID, "delete")
    delete_seccess_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")
    tj_locator = (By.LINK_TEXT, "推进")
    tj_stage_locator = (By.NAME, "status_id")
    tj_save_button_locator = (By.NAME, "submit")
    hsz_locator = (By.CSS_SELECTOR, "body > div.container > p > a:nth-child(17)")
    hsz_check_all_locator = (By.ID, "check_all")
    hsz_delete_locator = (By.ID, "delete")

    def click_hsz_delete(self):
        '''回收站点击删除'''
        self.find_element(self.hsz_delete_locator).click()

    def click_check_all(self):
        '''回收站点击勾选全部'''
        self.find_element(self.hsz_check_all_locator).click()

    def click_hsz(self):
        '''点击回收站'''
        self.find_element(self.hsz_locator).click()

    def click_delete(self):
        """点击商机页面删除按钮"""
        self.find_element(self.delete_locator).click()

    def click_gx(self):
        """点击勾选框"""
        self.find_element(self.gx_locator).click()

    def click_add_sj_btn(self):
        '''点击添加商机按钮'''
        self.find_element(self.add_sj_btn_locator).click()

    def click_push_btn(self):
        '''点击推进按钮'''
        self.find_element(self.tj_locator).click()

    def click_push_stage(self):
        '''选择推进商机到哪个阶段'''
        self.find_element(self.tj_stage_locator).click()

    def click_save_btn(self):
        '''点击保存按钮'''
        self.find_element(self.tj_save_button_locator).click()

    def push_success_text(self):
        try:
            text = self.find_element(self.push_success_locator).text
        except NoSuchElementException:
            text = ""
        return text

    def tips_success_text(self):
        try:
            text = self.find_element(self.tips_success_locator).text
        except NoSuchElementException:
            text = ""
        return text

    def delete_seccess_text(self):
        try:
            text = self.find_element(self.delete_seccess_locator).text
        except NoSuchElementException:
            text = ""
        return text
